package com.idanchuang.component.mq.amqp;

import com.idanchuang.component.config.apollo.ComponentConfigApolloAutoConfiguration;
import com.idanchuang.component.config.apollo.ConfigService;
import com.idanchuang.component.mq.amqp.switcher.apollo.ApolloConsumeSwitcher;
import com.idanchuang.component.mq.amqp.switcher.apollo.ApolloConsumeSwitcherRunner;
import org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yjy
 * @date 2019/11/8 11:12
 **/
@Configuration
@ConditionalOnBean(ConfigService.class)
@AutoConfigureAfter({ComponentConfigApolloAutoConfiguration.class, RabbitBootstrapConfiguration.class})
public class AmqpSwitchAutoConfiguration {

    @Bean
    public ApolloConsumeSwitcher apolloConsumeSwitcher() {
        return new ApolloConsumeSwitcher();
    }

    @Bean
    public ApolloConsumeSwitcherRunner apolloConsumeSwitcherRunner(ApolloConsumeSwitcher apolloConsumeSwitcher,
                                                                   RabbitListenerEndpointRegistry registry) {
        return new ApolloConsumeSwitcherRunner(apolloConsumeSwitcher, registry);
    }

}
